<?php
/**
 * Template Name: gotoGames
 *
 * 打开游戏前的转向页面。
 * date:2011/4/11 
 * @author Ryan 
 * 
 */

if (!isset($_SESSION)) {
 	session_start();
	//session_regenerate_id();
}


$gameid = $_GET['gameid'];
$game_url_key = "GameLink";

$gameLink = get_post_meta($gameid, $game_url_key, true);



$user = $_SESSION['userdata'];



$user_cookie = $_COOKIE['youxisoso_user'];

$user_cookie = explode(":", $user_cookie);

if (!$user_cookie){ //如果用户cookie不存在，则设置一个cookie；
	$custom_id = $user ? $user->ID :  uniqid();
	$user_cookie = array('ID'=> $custom_id , 'custom_type'=> $user ? '1' : '0');
	setcookie('youxisoso_user', join($user_cookie, ":"), time()+3600*24*30); 
}else{
	//如果用户cookie已经存在，且用户已登录的话，则判断cookie中记录的ID是否与登录用户一致，如果不一致将其ID设置为已登录的用户ID
	if($user && $user_cookie['ID'] != $user->ID){
		$user_cookie = array('ID'=> $user->ID , 'custom_type'=> '1'); 
		setcookie('youxisoso_user', join($user_cookie, ":"), time()+3600*24*30);
	}
}
//modify by yue 

//setCustomLog(array('custom_id'=>$user_cookie[0], 'custom_type'=>$user_cookie[1], 
			//'data'=>$gameid, 'data_type'=>1, 'custom_ip'=>GetIP(), 'op_date'=>gmdate('Y-m-d H:i:s')));
if(!$user_cookie[0]){ 
	setCustomLog(array('custom_id'=>$user_cookie['ID'], 'custom_type'=>$user_cookie['custom_type'], 
			'data'=>$gameid, 'data_type'=>1, 'custom_ip'=>GetIP(), 'op_date'=>gmdate('Y-m-d H:i:s')));
}else{
		setCustomLog(array('custom_id'=>$user_cookie[0], 'custom_type'=>$user_cookie[1], 
			'data'=>$gameid, 'data_type'=>1, 'custom_ip'=>GetIP(), 'op_date'=>gmdate('Y-m-d H:i:s')));	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php if ($gameLink){?>
<meta http-equiv="refresh" content="3; url=<?php echo $gameLink;?>" />
<?php }?>
<script type="text/javascript" src="<?php bloginfo('template_url');?>/js/showad.js"></script>
<title><?php wp_title("|", true, 'right'); bloginfo('name');?>页</title>
</head>
<body onload="showAD()">

<?php if($gameLink){
	setGameOpendCount($gameid);
	
	if($user){
		noteOpenedGame($user->ID, $gameid);
		
		if(!hasOpendGame($user->ID, $gameid)){
			addUserEmpiricalValue($user->ID, 20);
		}
	}
}else{
	echo "你要打开的游戏不存在，请确认是否正确，或联系管理员。";
}?>

</body>
</html>